﻿using System;

namespace MaximalIncreasingSequence
{
    class MaximalIncreasingSequence
    {
        static void PrintResult(int[] result)
        {
            if (result.Length > 1)
            {
                Console.Write("{ ");
                for (int index = 0, length = result.Length - 1; index < length; index++)
                {
                    Console.Write("{0}, ", result[index]);
                }
                Console.WriteLine("{0} }}", result[result.Length - 1]);
            }
            else
            {
                Console.WriteLine("Increasing sequence does not exist!");
            }
        }
        static int[] MaxIncreasingSequence(int[] numbers)
        {
            int[] result;
            int startIndex = 0,
                maxLength = 0,
                currentLength = 1;

            for (int index = 1, length = numbers.Length; index < length; index++)
            {
                if (numbers[index - 1] < numbers[index])
                {
                    currentLength++;
                }
                else
                {
                    if (currentLength > maxLength)
                    {
                        startIndex = index - currentLength;
                        maxLength = currentLength;
                    }
                    currentLength = 1;
                }
            }
            if (currentLength > maxLength)
            {
                startIndex = numbers.Length - currentLength;
                maxLength = currentLength;
            }

            result = new int[maxLength];
            Array.Copy(numbers, startIndex, result, 0, maxLength);
            return result;
        }
        static void Main(string[] args)
        {
            int arrayLength;
            int[] numbers;
            int[] result;

            Console.Write("Please enter the length of your array: ");
            arrayLength = int.Parse(Console.ReadLine());
            numbers = new int[arrayLength];
            for (int index = 0; index < arrayLength; index++)
            {
                Console.Write("Index [{0}]: ", index);
                numbers[index] = int.Parse(Console.ReadLine());
            }
            result = MaxIncreasingSequence(numbers);
            PrintResult(result);
        }
    }
}
